package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.TravelLike;
import cn.wolfcode.trip.base.query.TravelLikeQueryObject;
import cn.wolfcode.trip.base.service.ITravelLikeService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("travelLike")
public class TravelLikeController {

    @Autowired
    private ITravelLikeService travelLikeService;

    /**
     * 查询当前用户对该游记的点赞状态
     * @param travelLike
     * @return
     */
    @GetMapping("getStatus")
    public int getStatus(TravelLike travelLike){
        int status = travelLikeService.getStatusByLikerId(travelLike);
        return status;
    }

    /**
     * 当前用户对游记点赞
     * @param travelLike
     * @return
     */
    @PostMapping("addLike")
    public JSONResult addLike(TravelLike travelLike){
        travelLikeService.save(travelLike);
        return new JSONResult();
    }

    /**
     * 当前用户取消对该游记的点赞
     * @param travelLike
     * @return
     */
    @PostMapping("unlike")
    public JSONResult unLike(TravelLike travelLike){
        travelLikeService.delete(travelLike);
        return new JSONResult();
    }

    /**
     * 查询当前用户发表的游记被点赞的数目
     * @param userId 当前用户的id
     * @return
     */
    @GetMapping("getTravelLikerNum")//用户id,
    public int getTravelLikerNumById(Long userId){
        int num = travelLikeService.countNumBytravelId(userId);
        return num;
    }

    /**
     * 查询哪些人给我的游记点赞了
     * @param
     * @return
     */
    @GetMapping("getTravelLiker")
    public PageInfo getTravelLikerById(TravelLikeQueryObject qo){
        PageInfo pageInfo = travelLikeService.getTravelLikerById(qo);
        return pageInfo;
    }

    @PostMapping("changBrower")
    public JSONResult changBrowerStatus(Long userId){
        travelLikeService.changBrowerStatus(userId);
        return new JSONResult();
    }
}
